import requests
from bs4 import BeautifulSoup

class RequestUtil:
    response = ""
    responseList = []

    def __init__(self):
        responseList = []

    # 通过一个链接获取请求页面
    @staticmethod
    def get_request(url, types):
        response = requests.get(url)
        try:
            if response.status_code == 200:
                if types == 'text':
                    return response.text
                else:
                    return response.content
            else:
                print("获取链接失败" + url)
                return ''
        except IOError:
            print("获取链接错误:" + url)

    # 通过一组获取一组请求页面
    @staticmethod
    def get_list_request(url_list, types):
        response_list = []
        for url in url_list:
            response = RequestUtil.get_request(url, types)
            response_list.append(response)
        return response_list


    # 解析页面
    @staticmethod
    def parse_page(page, ruler):
        soup = BeautifulSoup(page)
        soup_page = soup.select(ruler)
        return soup_page



if __name__ == "__main__":
    RequestUtil.get_request()
